<template>
  <div class="login_css">
    <div class="login_box">
      <!-- 头像 -->
      <div class="avater_box">
      <img src="../assets/nbi.jpg"/>
      </div>
      <!-- 输入框 -->
      <el-form
        ref="ruleForm"
        :model="formInline"
        :rules="rules"
        label-width="0px"
        class="login_form"
      >
        <el-form-item prop="user">
          <el-input
            v-model="formInline.user"
            prefix-icon="iconfont icon-user"
            placeholder="请输入账号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="formInline.password"
            prefix-icon="iconfont icon-3702mima"
            placeholder="请输入密码"
            type="password"
          ></el-input>
        </el-form-item>
        <el-form-item class="btn_css">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info" @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        user: "",
        password: "",
      },
      users:[
        {user:"201810098332",password:"123456"},
        {user:"201810098092",password:"123456"},
        {user:"123456",password:"0000007"},
        {user:'admin',password:'123456'}
      ],
      rules: {
        user: [
          { required: true, message: "请输入账号", trigger: "blur" },
          {
            min: 3,
            max: 12,
            message: "长度在 3 到 12 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 15,
            message: "长度在 6 到 15 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    resetForm() {
      this.$refs.ruleForm.resetFields();
    },
    login() {
      this.$refs.ruleForm.validate((valid) => {
        if (!valid) return;
        let l=0;
        for(let i=0;i < this.users.length; i++){
          if(this.formInline.user==this.users[i].user&&this.formInline.password==this.users[i].password){
            this.$message({message: '登录成功',type: 'success',center: true});
            this.$router.push("/home");
            l=1
          }
        }
        if(l==0){
          this.$message({message: '账号密码错误！请重新输入！',type: 'error',center: true});
          this.formInline.password=""
        }
      });
    }
  },
};
</script>

<style lang="less" scoped>
.login_css {
  background-image: url("../assets/bg.jpg");
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  height: 100%;
}
.login_box {
  width: 450px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.avater_box {
  height: 130px;
  width: 130px;
  border: 1px solid #eee;
  border-radius: 50%;
  padding: 10px;
  box-shadow: 0 0 10px #ddd;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #eee;
  }
}
.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 30px;
  box-sizing: border-box;
}
.btn_css {
  text-align: center;
  /* 
    display: flex;
    justify-content: flex-end; */
}
</style>